#ifndef URLFILEDEALER_H_
#define URLFILEDEALER_H_

#include <iostream>
#include <list>

#include "../classes_dados/URLDiskClass.h"


#include "URL.h"
//#include <ext/hash_map>
#include <string>
#include <map>
#include <boost/tr1/memory.hpp>
#include <boost/thread/mutex.hpp>


#include "../classes_outros/Config.h"


class URLFileDealer{
private:
    URLFileDealer() 
    :maxNumUrlsFromDisk( Config::getMaxNumUrlsFromDisk() )
    { }
    
public:
    static std::tr1::shared_ptr<URLFileDealer> getInstance() {return theURLFileDealer;}
    std::list <URL *> getNewURLs();

    //~URLFileDealer(){ delete theURLFileDealer; }
    void initURLHashMap(URL _addUrl);
    void addURLs(std::list<URL>);
    void addToDiskBuffer(URL * url);
	
private:
	URLDiskClass discoUrl;	
    static std::tr1::shared_ptr<URLFileDealer> theURLFileDealer;
//	__gnu_cxx::hash_map<std::string, std::string> urlHashMap;
//	std::map<std::string, URL> urlHashMap; //velho
    std::map<std::string, bool> urlHashMap; //novo
    
	std::list <URL *> toDiskBuffer;
	boost::mutex diskBufferMutex;
	boost::mutex urlHashMapMutex;
	const uint maxNumUrlsFromDisk;

	std::list<URL> listURLtoWrite;
	std::list<URL> listURLtoRead;
};

#endif /*URLFILEDEALER_H_*/
